<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="/static/css/font.css">
    <link rel="stylesheet" href="/static/css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="/static/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/static/js/xadmin.js"></script>
    <style>
        .aaa{cursor: pointer;}
    </style>
</head>

<body class="layui-anim layui-anim-up">
<div class="x-body">
    <xblock>
        <button class="layui-btn" onclick="add()"><i class="layui-icon"></i>添加临时菜品</button>
        <div class="x-right" style="line-height:40px">共有数据：{$data.count}条</div>
    </xblock>
    <table class="layui-table">
        <thead>
        <tr>
            <th>
                <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i class="layui-icon">&#xe605;</i></div>
            </th>
            <th>ID</th>
            <th>名称</th>
            <th>图片</th>
            <th>规格</th>
            <th>当前数量</th>
            <th>退回数量</th>
            <th>单价</th>
            <th>厨师</th>
            <th>操作</th></tr>
        </thead>
        <tbody>
        {volist name="data.list" id="vo"}
        <tr>
            <td>
                <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='{$vo.id}'><i class="layui-icon">&#xe605;</i></div>
            </td>
            <td>{$vo.id}</td>
            <td>{$vo.food_name}</td>
            <td><img src="{$vo.image}" height="40px;"/></td>
            <td>{$vo.spec}</td>
            <td>{$vo.quantity}</td>
            <td>{$vo.return_number}</td>
            <td>{$vo.food_price}</td>
            <td>{$vo.cook_id}</td>
            <td class="td-manage">
                <a title="退菜" onclick="order_food('{$vo.id}','{$vo.quantity}')" class="layui-btn layui-btn-sm">退回</a>
            </td>
        </tr>
        {/volist}
        </tbody>
    </table>
</div>
<form class="layui-form" id="form" hidden>
    <input type="hidden" name="order_no" value="{$data.order_no}">
    {volist name="data.temporary" id="vo"}
    <div class="layui-form-item">
        <div class="layui-input-inline" style="width: 100px;margin-left: 10px;">
            <input type="checkbox" name="food_id[]" value="{$vo.id}" title="{$vo.food_name}" class="layui-input">
        </div>
        <div class="layui-form-mid">-</div>
        <div class="layui-input-inline" style="width: 100px;">
            <input type="number" name="number[{$vo.id}]" disabled placeholder="请输入数量" autocomplete="off" class="layui-input">
        </div>
    </div>
    {/volist}
</form>
<script>
    layui.use('form', function(){
        var form = layui.form;
        form.on('checkbox()',function (data) {
            if (data.elem.checked){
                $(data.elem).parent('.layui-input-inline').next().next().children("input").removeAttr('disabled');
                form.render();
            }else {
                $(data.elem).parent().next().next().children("input").val('');
                $(data.elem).parent().next().next().children("input").attr('disabled','disabled');
                form.render();
            }
        });
    });

    function add() {
        layer.open({
            type: 1,
            title:'加菜',
            content:$('#form'),
            btn:['确认','取消'],
            yes:function (index, layero) {
                var data = $('.layui-form').serializeArray();
                $.post('{:url("order/orderAddTemp")}',data,function (res) {
                    // console.log(res);
                    if (res.code == 1){
                        layer.msg(res.msg,{icon:6,time:1000},function () {
                            window.location.reload();
                            layer.close(index);
                        });
                    } else {
                        layer.msg(res.msg,{icon:5,time:2000});
                    }
                });
            }
        });
    }
    function order_food(id,number) {
        layer.prompt({
            title:'请输入退回数量',
            value: number
        },function(value, index, elem){
            $.post('{:url("order/foodReturn")}',{number:value,id:id},function (res) {
                if (res.code == 1){
                    layer.msg(res.msg,{icon:1,time:1000},function () {
                        window.location.reload();
                        layer.close(index);
                    });
                } else {
                    layer.msg(res.msg,{icon:2,time:1000});
                }
            });
        });
    }
    /*用户-停用*/
    function member_stop(obj,id){
        layer.confirm('确认要停用吗？',function(index){

            if($(obj).attr('title')=='启用'){

                //发异步把用户状态进行更改
                $(obj).attr('title','停用')
                $(obj).find('i').html('&#xe62f;');

                $(obj).parents("tr").find(".td-status").find('span').addClass('layui-btn-disabled').html('已停用');
                layer.msg('已停用!',{icon: 5,time:1000});

            }else{
                $(obj).attr('title','启用')
                $(obj).find('i').html('&#xe601;');

                $(obj).parents("tr").find(".td-status").find('span').removeClass('layui-btn-disabled').html('已启用');
                layer.msg('已启用!',{icon: 5,time:1000});
            }

        });
    }

    /*用户-删除*/
    function member_del(obj,id){
        layer.confirm('确认要删除吗？',function(index){
            //发异步删除数据
            $(obj).parents("tr").remove();
            layer.msg('已删除!',{icon:1,time:1000});
        });
    }



    function delAll (argument) {

        var data = tableCheck.getData();

        layer.confirm('确认要删除吗？'+data,function(index){
            //捉到所有被选中的，发异步进行删除
            layer.msg('删除成功', {icon: 1});
            $(".layui-form-checked").not('.header').parents('tr').remove();
        });
    }
</script>
</body>

</html>